package cn.gok.demolast.controller;


import cn.gok.demolast.dao.ClazzMapper;
import cn.gok.demolast.entity.Clazz;
import cn.gok.demolast.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 李xx
 * @since 2022-07-21
 */
@RestController
@RequestMapping("/clazz")
public class ClazzController {
    @Autowired
    private ClazzMapper clazzMapper;
    Clazz clazz = new Clazz();

    //    查询所有
    @RequestMapping("/selectAllClazz")
    public List<Clazz> selectAllClazz() {
        return clazzMapper.selectList(null);
    }

    //    2）根据ID查询班级信息
    @RequestMapping("/selectId")
    public Clazz selectId() {
        return clazzMapper.selectById(1);
    }

    // 3）查询所有班级信息和对应的学生信息
    @RequestMapping("/selectByClazzAndS")
    public List<Clazz> selectByClazzAndS() {
        List<Clazz> clazzes = clazzMapper.selectByClazzAndS();
        return clazzes;
    }

    //    4）添加班级
    @RequestMapping("/addClazz")
    public void addClazz() {
        int rows;
        clazz.setCname("3班");
        rows = clazzMapper.insert(clazz);
        System.out.println(rows);
    }

    //    5）修改班级信息
    @RequestMapping("/updateClazz")
    public void updateClazz() {
        int rows;
        clazz.setCid(3L);
        clazz.setCname("三班");
        rows = clazzMapper.updateById(clazz);
        System.out.println(rows);
    }

    //    6）根据id删除班级
    @RequestMapping("/deletedById")
    public Integer deletedById(@RequestParam Long id) {
        return clazzMapper.deleteById(id);
    }

    //    7）批量删除班级
    @RequestMapping("/deletedByIds")
    public Integer deletedByIds(@RequestBody List<Integer> ids) {
        return clazzMapper.deleteBatchIds(ids);
    }
}

